package com.wswy.wzcx.utils;

import android.content.Context;
import android.os.Build;
import android.view.View;

/**
 * Created by wangduheng26 on 2018/2/6.
 * wangduheng26@gmail.com
 */

public class StatusBarCompat {
    public static int STATUS_BAR_HEIGHT = -1;

    public static void init(Context context) {
        STATUS_BAR_HEIGHT = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            STATUS_BAR_HEIGHT = context.getResources().getDimensionPixelSize(resourceId);
        }
//        Log.e("WangJ", "状态栏-方法1:" + statusBarHeight1);
    }

    public static void setup(View view) {
        if (view == null) return;
        if (STATUS_BAR_HEIGHT == -1) {
            synchronized (StatusBarCompat.class) {
                init(view.getContext());
            }
        }

        if (isM()) {
            view.setPadding(0, STATUS_BAR_HEIGHT, 0, 0);
        } else {
            view.setPadding(0, 0, 0, 0);
        }
    }

    public static boolean isM(){
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
    }
}
